package cn.gjxblog.modules.third.oss;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @Author guojiaxun
 * @Date 2019/9/17 13:58
 */
@Component
public class OssServiceContext  {

    private final Map<Integer,IOssService> maps = new ConcurrentHashMap<>();

    /**
     * 构造方式注入
     * @param ossMaps
     */
    @Autowired
    public OssServiceContext(Map<String,IOssService> ossMaps) {
        maps.clear();
        ossMaps.forEach((k,v)-> maps.put(OssTypeEnum.geTypeByName(k),v));
    }


    private IOssService getOssService(Integer type){
        return  maps.get(type);
    }

    public String upload(Integer strategyType,byte[] data, String path) {
      return  getOssService(strategyType).upload(data,path);
    }
}
